﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace FierceWar
{
	class GameLevel : Level
	{
		private ModelType[] _enemiesType = new ModelType[] {
				  ModelType.Ship1,
				  ModelType.Ship3,
				  ModelType.Ship4,
				  ModelType.Ship5,
				  ModelType.Ship6,
				  ModelType.Ship7,
				  ModelType.Ship8,
				  ModelType.Ship9,
				  ModelType.Helicopter,
		};

        private GameResources _resource;

        public List<Enemy> _enemies;
		private int _rangeX;
		private int _rangeY;
		private int _rangeZ;
		private int _velocity;

        public GameLevel(int level, GameResources resources)
			: base(level)
		{
            _level = level;
            _resource = resources;
			_rangeX = 3000;
			_rangeY = 1000;
			_rangeZ = 3000;
			_velocity = 50;
            NextLevel();
		}

        public void NextLevel()
        {
            _level++;
			LoadEnemies((int)MathHelper.Clamp(_level + 3, 4, 15));

			_rangeX = (int)MathHelper.Clamp(_rangeX + 1000, 3000, 10000);
			_rangeY = (int)MathHelper.Clamp(_rangeY + 500, 1000, 5000);
			_rangeZ = (int)MathHelper.Clamp(_rangeZ + 1000, 3000, 10000);
			_velocity = (int)MathHelper.Clamp(_velocity + 20, 50, 150);
        }

		private void LoadEnemies(int number)
		{
			_enemies = new List<Enemy>();
			Random random = new Random();
			for (int i = 0; i < number; i++)
			{
				ModelType type = _enemiesType[random.Next(_enemiesType.Length)];
				_enemies.Add(new Enemy(_resource.Content, type,
					new Vector3(
						random.Next(_rangeX),
						random.Next(1000, _rangeY),
						random.Next(_rangeZ)),
					_velocity));
			}
		}
	}
}
